//
//  LSLiveCell.m
//  LookScore
//
//  Created by wws on 2018/3/23.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSLiveCell.h"
#import "LSLiveModel.h"

@implementation LSLiveOneView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = LSBackGroundColor;
        self.teamLabel = [[UILabel alloc] init];
        self.teamLabel.textAlignment = NSTextAlignmentCenter;
        self.teamLabel.textColor = RGB(180,180,180);
        self.teamLabel.font = LSFontSize13;
        self.teamLabel.backgroundColor = RGB(247,247,247);
        [self addSubview:self.teamLabel];
        
        self.teamLabel.sd_layout
        .leftEqualToView(self)
        .rightEqualToView(self)
        .topEqualToView(self)
        .heightIs(frame.size.height/3.0);
        
        self.hostTeamLabel = [[UILabel alloc] init];
        self.hostTeamLabel.textAlignment = NSTextAlignmentCenter;
        self.hostTeamLabel.textColor = RGB(93,93,93);
        self.hostTeamLabel.font = LSFontSize13;
        self.hostTeamLabel.backgroundColor = LSBackGroundColor;
        [self addSubview:self.hostTeamLabel];
        self.hostTeamLabel.sd_layout
        .leftEqualToView(self)
        .rightEqualToView(self)
        .topSpaceToView(self.teamLabel, 0)
        .heightIs(frame.size.height/3.0);
        
        self.gustTeamLabel = [[UILabel alloc] init];
        self.gustTeamLabel.textAlignment = NSTextAlignmentCenter;
        self.gustTeamLabel.textColor = RGB(93,93,93);
        self.gustTeamLabel.font = LSFontSize13;
        self.gustTeamLabel.backgroundColor = RGB(247,247,247);
        [self addSubview:self.gustTeamLabel];
        self.gustTeamLabel.sd_layout
        .leftEqualToView(self)
        .rightEqualToView(self)
        .topSpaceToView(self.hostTeamLabel, 0)
        .heightIs(frame.size.height /3.0);
        
        
        
    }
    return self;
}

@end


@interface LSLiveOneCell()
@property (nonatomic, strong) NSMutableArray * titleArray;


@end
@implementation LSLiveOneCell{
    UILabel * _hostLabel;//主队
    UILabel * _cornerLabel;//角球
    UILabel * _onTargetLabel;//射正球门
    UILabel * _shotWideLabel;//射偏球门
    UILabel * _aShotLabel;//射门
    UILabel * _remedialLabel;//补救
    UIView * _bgView;
    
    
}


+ (LSLiveOneCell *)liveOneTableViewCellBytableView:(UITableView *)tableView{
    
    LSLiveOneCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[LSLiveOneCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    
    return self;
}


- (void)setDataArray:(NSMutableArray *)dataArray{
    _dataArray = dataArray;
    CGFloat width=(LSScreenWidth) / 6;
    CGFloat height = 90;
    if (dataArray.count <= 0) {
        return;
    }
    for (NSInteger i = 0; i< dataArray.count; i++) {
        
//        if (<#condition#>) {
//            <#statements#>
//        }
        
        
        
        
        if (i % 5 == 0) {
            LSLiveOneView * view1 = [[LSLiveOneView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
            [_bgView addSubview:view1];
            view1.teamLabel.text = @"球队";
            view1.hostTeamLabel.text = @"主";
            view1.gustTeamLabel.text = @"客";
            view1.sd_layout
            .leftEqualToView(0)
            .topSpaceToView(_bgView, (i/5) *(height + 10))
            .widthIs(width)
            .heightIs(height);
        }
        LSLiveOneView * view;
        if (!view) {
            view = [[LSLiveOneView alloc] initWithFrame:CGRectMake(0, 0, 0, height)];
            [_bgView addSubview:view];
        }
        
        if (i<5) {
            
            
            view.sd_layout
            .leftSpaceToView(_bgView, (i + 1) * width)
            .topEqualToView(_bgView)
            .widthIs(width)
            .heightIs(height);
        }else if (i>=5 && i<10){
            
            view.sd_layout
            .leftSpaceToView(_bgView, (i - 5 + 1) * width)
            .topSpaceToView(_bgView, (i/5)*height + 10)
            .widthIs(width)
            .heightIs(height);
            
        }else if (i>= 10 && i<15){
            
            view.sd_layout
            .leftSpaceToView(_bgView, (i - 10 + 1) * width)
            .topSpaceToView(_bgView, (i/5)*(height + 10))
            .widthIs(width)
            .heightIs(height);
            
        }else if (i>=15 && i<20){
            view.sd_layout
            .leftSpaceToView(_bgView, (i - 15 + 1) * width)
            .topSpaceToView(_bgView, (i/5)*(height + 10))
            .widthIs(width)
            .heightIs(height);
            
        }
        
        if (i == dataArray.count - 1) {
            [self setupAutoHeightWithBottomView:view bottomMargin:5];
//            [self setup]
//            self.cellH = (i/5)*(height + 10) + height;
            
        }
        
        LSReportList * model = dataArray[i];
        view.teamLabel.text = model.ReportItemName_CN;
        view.hostTeamLabel.text = model.HomeTeamData;
        view.gustTeamLabel.text = model.GuestTeamData;
        
    }
    
    
}


-(void)addContentView{
    _bgView = [[UIView alloc] init];
    [self.contentView addSubview:_bgView];
    _bgView.sd_layout
    .leftEqualToView(self.contentView)
    .topEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .bottomEqualToView(self.contentView);
    
}


@end


@implementation LSLiveCell{
    
    UILabel * _middleLabel;
    UIImageView * _middelImageView;
    
    UILabel * _leftLabel;
    UIImageView * _leftImageView;
    
    UILabel * _rightLabel;
    UIImageView * _rightImageView;
    
    
    UIImageView * _leftBgView;
    UIImageView * _rigtBgView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+ (LSLiveCell *)liveTableViewCellByTabView:(UITableView *)tableView{
    LSLiveCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[LSLiveCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.backgroundColor = LSBackGroundColor;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    return self;
    
}


- (void)addContentView{
    
    _middleLabel = [[UILabel alloc] init];
    _middleLabel.text = @"1:1";
    _middleLabel.textColor = RGB(93,93,93);
    _middleLabel.backgroundColor = RGB(219,219,219);
    _middleLabel.font = LSFontSize11;
    _middleLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_middleLabel];
    _middleLabel.sd_layout
    .centerXEqualToView(self.contentView)
    .topSpaceToView(self.contentView, 10)
    .heightIs(14)
    .widthIs(30);
    
    
    
    _leftBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"leftBg"]];
    [self.contentView addSubview:_leftBgView];
    _leftBgView.hidden = YES;
    _leftBgView.sd_layout
    .leftSpaceToView(self.contentView, 14)
    .rightSpaceToView(_middleLabel, 6)
    .topSpaceToView(self.contentView, 7)
    .heightIs(34);
    
    _rigtBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rightBg"]];
    [self.contentView addSubview:_rigtBgView];
    _rigtBgView.hidden = YES;
    _rigtBgView.sd_layout
    .leftSpaceToView(_middleLabel, 6)
    .rightSpaceToView(self.contentView, 14)
    .topSpaceToView(self.contentView, 7)
    .heightIs(34);
    
    _middelImageView = [[UIImageView alloc] init];
    _middelImageView.hidden = YES;
    [self.contentView addSubview:_middelImageView];
   _middelImageView.sd_layout
    .centerYEqualToView(self.contentView)
    .centerXEqualToView(self.contentView)
    .heightIs(14)
    .widthIs(14);

    _topView = [[UIImageView alloc] init];
//    _topView.backgroundColor = LSLineGrayColor;
    _topView.backgroundColor = LSLineGrayColor;
    [self.contentView addSubview:_topView];
    _topView.sd_layout
    .centerXEqualToView(self.contentView)
    .topEqualToView(self.contentView)
    .bottomSpaceToView(_middleLabel, 0).widthIs(1);
    
    _rightImageView = [[UIImageView alloc] init];
//    _rightImageView.backgroundColor = [UIColor redColor];
    [_rigtBgView addSubview:_rightImageView];
    _rightImageView.sd_layout
    .leftSpaceToView(_rigtBgView, 5)
    .centerYEqualToView(_rigtBgView)
    .widthIs(14)
    .heightIs(14);
    
    _rightLabel = [[UILabel alloc] init];
    _rightLabel.text = @"第一个";
    _rightLabel.textColor = RGB(25,25,25);
    _rightLabel.font = LSFontSize10;
    _rightLabel.textAlignment = NSTextAlignmentLeft;
    [_rigtBgView addSubview:_rightLabel];
    _rightLabel.sd_layout
    .leftSpaceToView(_rightImageView, 8)
    .centerYEqualToView(_rigtBgView)
    .rightSpaceToView(_rigtBgView, 0)
    .autoHeightRatio(0);
    
    
    
    _leftImageView = [[UIImageView alloc] init];
//    _leftImageView.backgroundColor = [UIColor redColor];
    [_leftBgView addSubview:_leftImageView];
    
    _leftImageView.sd_layout
    .rightSpaceToView(_leftBgView, 8)
    .centerYEqualToView(_leftBgView)
    .heightIs(14)
    .widthIs(14);
    
    _leftLabel = [[UILabel alloc] init];
    _leftLabel.text = @"第二个";
    _leftLabel.textColor = RGB(25,25,25);
    _leftLabel.textAlignment = NSTextAlignmentRight;
    _leftLabel.font = LSFontSize10;
    [_leftBgView addSubview:_leftLabel];
    _leftLabel.sd_layout
    .rightSpaceToView(_leftImageView, 5)
    .centerYEqualToView(_leftImageView)
    .leftEqualToView(self.contentView)
    .autoHeightRatio(0);
   
    
    _bottomView = [[UIImageView alloc] init];
    _bottomView.backgroundColor = LSLineGrayColor;
    [self.contentView addSubview:_bottomView];
    _bottomView.sd_layout
    .centerXEqualToView(self.contentView)
    .topSpaceToView(_middleLabel, 0)
    .bottomEqualToView(self.contentView)
    .widthIs(1);
    
    
}

- (void)setEventModel:(LSEventList *)eventModel{
    _eventModel = eventModel;
    
    
    _middleLabel.text = [NSString stringWithFormat:@"%ld",eventModel.EventMinutes];
    
    switch (eventModel.EventCode) {
        case 1:{
            //进球
            _leftImageView.image = [UIImage imageNamed:@"jin"];
            _rightImageView.image = [UIImage imageNamed:@"jin"];
        }
            break;
        case 2:{
            //红牌
            _leftImageView.image = [UIImage imageNamed:@"hong"];
            _rightImageView.image = [UIImage imageNamed:@"hong"];
        }
            break;
        case 3:{
            //黄牌
            _leftImageView.image = [UIImage imageNamed:@"huang"];
            _rightImageView.image = [UIImage imageNamed:@"huang"];
        }
            break;
        case 11:{
            //换人
            _leftImageView.image = [UIImage imageNamed:@"huan"];
            _rightImageView.image = [UIImage imageNamed:@"huan"];
        }
            break;
        case 5:{
            _leftImageView.image = [UIImage imageNamed:@"huanchu"];
            _rightImageView.image = [UIImage imageNamed:@"huanchu"];
        }
            break;
        case 6:{
            _leftImageView.image = [UIImage imageNamed:@"lianghuangyihong"];
            _rightImageView.image = [UIImage imageNamed:@"lianghuangyihong"];
        }
            break;
        case 7:{
            //点球
            _leftImageView.image = [UIImage imageNamed:@"dian"];
            _rightImageView.image = [UIImage imageNamed:@"dian"];
            
        }
            break;
        case 8:{
            //乌龙
            _leftImageView.image = [UIImage imageNamed:@"wulong"];
            _rightImageView.image = [UIImage imageNamed:@"wulong"];
        }
            break;
        case 9:{
            //两黄变红
            _leftImageView.image = [UIImage imageNamed:@"lianghuang"];
            _rightImageView.image = [UIImage imageNamed:@"lianghuang"];
        }
            break;
        case 4:{
            _leftImageView.image = [UIImage imageNamed:@"huanru"];
            _rightImageView.image = [UIImage imageNamed:@"huanru"];
        }
            break;
        
        default:
            break;
    }
//    _rightLabel.hidden = YES;
//    _leftLabel.hidden = YES;
    
    
    if (eventModel.HomeOrGuest == 1) {
        
        _rightImageView.hidden = YES;
        _rightLabel.hidden = YES;
        _leftImageView.hidden = NO;
        _leftLabel.hidden = NO;
        _leftLabel.text = [NSString stringWithFormat:@"%@%@",eventModel.EventLeader_CN,eventModel.EventName];
        
        _rigtBgView.hidden = YES;
        _leftBgView.hidden = NO;
        
    }else{
        
        _rightImageView.hidden = NO;
        _leftImageView.hidden = YES;
        _leftLabel.hidden = YES;
        _rightLabel.hidden = NO;
        _rightLabel.text = [NSString stringWithFormat:@"%@%@",eventModel.EventLeader_CN,eventModel.EventName];
        _rigtBgView.hidden = NO;
        _leftBgView.hidden = YES;
    }
    
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end




@implementation LSLiveDataCell{
    UILabel * _middleLabel;
    UIImageView * _middelImageView;
    
    UILabel * _leftLabel;
    UIImageView * _leftImageView;
    
    UILabel * _rightLabel;
    UIImageView * _rightImageView;
    
    
    UIImageView * _leftBgView;
    UIImageView * _rigtBgView;
}
+ (LSLiveDataCell *)liveDataTableViewCellByTabView:(UITableView *)tableView{
    LSLiveDataCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[LSLiveDataCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.backgroundColor = LSBackGroundColor;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    return self;
    
}


- (void)addContentView{
    
    _middleLabel = [[UILabel alloc] init];
    _middleLabel.text = @"1:1";
    _middleLabel.textColor = RGB(93,93,93);
    _middleLabel.backgroundColor = RGB(219,219,219);
    _middleLabel.font = LSFontSize11;
    _middleLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_middleLabel];
    _middleLabel.sd_layout
    .centerXEqualToView(self.contentView)
    .topSpaceToView(self.contentView, 10)
    .heightIs(14)
    .widthIs(30);
    
    
    
    _leftBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"leftBg"]];
    [self.contentView addSubview:_leftBgView];
    _leftBgView.hidden = YES;
    _leftBgView.sd_layout
    .leftSpaceToView(self.contentView, 14)
    .rightSpaceToView(_middleLabel, 6)
    .topSpaceToView(self.contentView, 7)
    .heightIs(34);
    
    _rigtBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rightBg"]];
    [self.contentView addSubview:_rigtBgView];
    _rigtBgView.hidden = YES;
    _rigtBgView.sd_layout
    .leftSpaceToView(_middleLabel, 6)
    .rightSpaceToView(self.contentView, 14)
    .topSpaceToView(self.contentView, 7)
    .heightIs(34);
    
    _middelImageView = [[UIImageView alloc] init];
    _middelImageView.hidden = YES;
    [self.contentView addSubview:_middelImageView];
    _middelImageView.sd_layout
    .centerYEqualToView(self.contentView)
    .centerXEqualToView(self.contentView)
    .heightIs(14)
    .widthIs(14);
    
    _topView = [[UIImageView alloc] init];
    //    _topView.backgroundColor = LSLineGrayColor;
    _topView.backgroundColor = LSLineGrayColor;
    [self.contentView addSubview:_topView];
    _topView.sd_layout
    .centerXEqualToView(self.contentView)
    .topEqualToView(self.contentView)
    .bottomSpaceToView(_middleLabel, 0).widthIs(1);
    
//    _rightImageView = [[UIImageView alloc] init];
//    //    _rightImageView.backgroundColor = [UIColor redColor];
//    [_rigtBgView addSubview:_rightImageView];
//    _rightImageView.sd_layout
//    .leftSpaceToView(_rigtBgView, 5)
//    .centerYEqualToView(_rigtBgView)
//    .widthIs(14)
//    .heightIs(14);
    
    _rightLabel = [[UILabel alloc] init];
    _rightLabel.text = @"第一个";
    _rightLabel.textColor = RGB(25,25,25);
    _rightLabel.font = LSFontSize10;
    _rightLabel.textAlignment = NSTextAlignmentLeft;
    [_rigtBgView addSubview:_rightLabel];
    _rightLabel.sd_layout
    .leftSpaceToView(_rigtBgView, 5)
    .centerYEqualToView(_rigtBgView)
    .rightSpaceToView(_rigtBgView, 0)
    .autoHeightRatio(0);
    
    
    
//    _leftImageView = [[UIImageView alloc] init];
//    //    _leftImageView.backgroundColor = [UIColor redColor];
//    [_leftBgView addSubview:_leftImageView];
//
//    _leftImageView.sd_layout
//    .rightSpaceToView(_leftBgView, 8)
//    .centerYEqualToView(_leftBgView)
//    .heightIs(14)
//    .widthIs(14);
    
    _leftLabel = [[UILabel alloc] init];
    _leftLabel.text = @"第二个";
    _leftLabel.textColor = RGB(25,25,25);
    _leftLabel.textAlignment = NSTextAlignmentRight;
    _leftLabel.font = LSFontSize10;
    [_leftBgView addSubview:_leftLabel];
    _leftLabel.sd_layout
    .rightSpaceToView(_leftBgView, 5)
    .centerYEqualToView(_leftBgView)
    .leftEqualToView(_leftBgView)
    .autoHeightRatio(0);
    
    
    _bottomView = [[UIImageView alloc] init];
    _bottomView.backgroundColor = LSLineGrayColor;
    [self.contentView addSubview:_bottomView];
    _bottomView.sd_layout
    .centerXEqualToView(self.contentView)
    .topSpaceToView(_middleLabel, 0)
    .bottomEqualToView(self.contentView)
    .widthIs(1);
    
    
}

- (void)setHostId:(NSInteger)hostId{
    _hostId = hostId;
    
}

- (void)setGuestId:(NSInteger)guestId{
    
    _guestId = guestId;
    
}

- (void)setLiveDataModel:(LSLiveDataEvent *)liveDataModel{
    _liveDataModel = liveDataModel;
    _leftImageView.hidden = YES;
    _rightImageView.hidden = YES;
    _rightLabel.text = [NSString stringWithFormat:@"%@",liveDataModel.EventName_CN];
    _leftLabel.text = liveDataModel.EventName_CN;
    _leftLabel.hidden = YES;
    _rightLabel.hidden = YES;
    
    if (liveDataModel.TeamId == 0) {
        _middleLabel.text = liveDataModel.EventName_CN;
    }else{
        _middleLabel.text = liveDataModel.Time;
    }
    
    if (liveDataModel.TeamId == self.guestId) {
        _leftLabel.hidden = YES;
        _leftBgView.hidden = YES;
        _rightLabel.hidden = NO;
        _rigtBgView.hidden = NO;
        
       
        
    }else if(liveDataModel.TeamId == self.hostId){
        _rightLabel.hidden = YES;
        _rigtBgView.hidden = YES;
        _leftBgView.hidden = NO;
        _leftLabel.hidden = NO;
       
    }
    
    
    
}
@end


